package com.small.common.util.page;

import com.small.common.base.ConstantPattern;

import javax.validation.constraints.Pattern;
import java.io.Serializable;

/**
 * 作者: fenny
 * 邮箱: 893146555@qq.com
 * 时间: 2017/10/23 18:22
 * 描述: 分页参数基类
 */
public class PageBeanParam implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 开始行
     */
    private int offset;
    /**
     * 当前页码
     */
    private int page;

    /**
     * 结束行
     */
    private int limit = 10;

    /**
     * 需要排序字段
     */
    private String sort;

    /**
     * 降序desc 升序 asc
     */
    @Pattern(regexp = ConstantPattern.VAL_ASC_DESC)
    private String order;

    public int getOffset() {
        return offset;
    }

    public void setOffset(int offset) {
        this.offset = offset;
    }

    public int getLimit() {
        return limit;
    }

    public void setLimit(int limit) {
        this.limit = (limit <= 0 ? 10 : limit);
    }

    public String getSort() {
        return sort;
    }

    public void setSort(String sort) {
        this.sort = sort;
    }

    public String getOrder() {
        return order;
    }

    public void setOrder(String order) {
        this.order = order;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
        if(page>0){
            offset = (page - 1) * limit;
        }
    }
}
